<?php
/**
 * User: Mykola B.
 * Date: 3/3/13
 * Time: 2:36 PM
 */
namespace geo {
    class PointCollection implements \Iterator
    {
        private $position = 0;
        /**
         * @var Point[]
         */
        private $points = array();

        /**
         * @param \DB\SQL\Mapper $objects
         */
        public function __construct(array $carPositions) {
            $this->position = 0;
            foreach ($carPositions as $carPosition) {
                $point = new Point($carPosition->latitude, $carPosition->longitude, $carPosition);
                array_push($this->points, $point);
            }
        }

        public function rewind() {
            $this->position = 0;
        }

        public function current() {
            return $this->points[$this->position];
        }

        public function key() {
            return $this->position;
        }

        public function next() {
            ++$this->position;
        }

        public function valid() {
            return isset($this->points[$this->position]);
        }
    }
}
